package group.rober.jeki.controller

import group.rober.jeki.entity.Comment
import group.rober.jeki.service.CommentService
import group.rober.saber.kit.NumberKit
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.servlet.ModelAndView

@Controller
@RequestMapping("/tweet")
class TweetController {
    @Autowired
    CommentService commentService;

    @RequestMapping(path="/send",method = RequestMethod.POST)
    public ModelAndView sendTweet(@RequestParam("content") String content){
        Comment comment = new Comment();
        comment.setId(NumberKit.nanoTime36());
        comment.setContent(content);
        comment.setType("Tweet")

        commentService.addComment(comment);

        return new ModelAndView("redirect:/");
    }
}
